package good

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"homepage_srv/homepageclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddCommentLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddCommentLogic {
	return &AddCommentLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 一级评论添加
func (l *AddCommentLogic) AddComment(req *types.AddCommentRequest) (resp *types.Response, err error) {
	comment, err := l.svcCtx.HomepageGrpc.AddComment(l.ctx, &homepageclient.AddCommentRequest{
		GoodId:  req.GoodId,
		UserId:  req.UserId,
		Content: req.Content,
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}

	return respons.Success(comment), nil
}
